package applet.forces;

import java.awt.geom.Point2D;
import applet.Simulation;

/**
 * Holds all of the data for a wall's force. Which wall is
 * specified by the id. The info is then put into a list
 * that is tracked by GlobalForce.
 *
 * @author Guy Tracy and Jesse Starr
 *
 */
public class WallData {

    private double myMagnitude;
    private double myExponent;
    private int myID;
    private double myAngle;
    private boolean myOnOff;

    /**
     * Constructs a wall force for a wall
     * depending on the id.
     * @param magnitude of force
     * @param exponent of force
     * @param id of wall
     */
    public WallData(double magnitude, double exponent, int id) {
        myMagnitude = magnitude;
        myExponent = exponent;
        myID = id;
        myOnOff = true;

        if (id == 1) {
            myAngle = 90;
        }
        else if (id == 2) {
            myAngle = 180;
        }
        else if (id == 3) {
            myAngle = 270;
        }
        else {
            myAngle = 0;
        }
    }

    /**
     * Returns the repulsion force for this wall.
     *
     * @param canvas for the bounds
     * @param pointCenter for the mass
     * @return
     */
    public Force getWallForce(Simulation canvas, Point2D pointCenter) {
        double distance = 0;

        if (myID == 1) {
            distance = pointCenter.getY() - canvas.getTop();
        }
        else if (myID == 2) {
            distance = canvas.getRight() - pointCenter.getX();
        }
        else if (myID == 3) {
            distance = canvas.getBottom() - pointCenter.getY();
        }
        else if (myID == 4) {
            distance = pointCenter.getX() - canvas.getLeft();
        }

        double tempVal = 1 / Math.pow(distance, myExponent);

        Force wallForce = new Force(myAngle, tempVal);
        wallForce.scale(myMagnitude);

        return wallForce;
    }

    /**
     * Returns this wall's id.
     * @return
     */
    public int getID() {
        return myID;
    }

    /**
     * Toggles this wall's force.
     */
    public void toggle() {
        if (!myOnOff) {
            myOnOff = true;
        }
        else {
            myOnOff = false;
        }
    }

    /**
     * Checks if this wall's force is on/off.
     */
    public boolean checkWall() {
        return myOnOff;
    }
}
